package com.jeomo.common.quartz.starter.service.impl;

import com.jeomo.base.starter.service.impl.BaseServiceImpl;
import com.jeomo.common.core.dto.PageQueryDto;
import com.jeomo.common.core.dto.PageResponseDto;
import com.jeomo.common.quartz.starter.entity.JobAndTrigger;
import com.jeomo.common.quartz.starter.mapper.JobAndTriggerMapper;
import com.jeomo.common.quartz.starter.service.BaseJob;
import com.jeomo.common.quartz.starter.service.IJobAndTriggerService;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * <h3>springboot-quartz</h3>
 * <p>分页实现</p>
 *
 * @author : 崔贺
 * @date : 2020-08-18 09:10
 **/
@Service
public class IJobAndTriggerServiceImpl extends BaseServiceImpl<JobAndTriggerMapper, JobAndTrigger> implements IJobAndTriggerService {


    @Override
    public PageResponseDto pageSearch(PageQueryDto dt) {

        PageResponseDto pageResponseDto = super.pageSearch(dt);
        List<?> items = pageResponseDto.getItems();
        Iterator<?> iterator = items.iterator();
        a:while(iterator.hasNext()){
            JobAndTrigger jobAndTrigger = (JobAndTrigger)iterator.next();
            String jobClassName = jobAndTrigger.getJobClassName();
            try {
                Class<?> clazz = Class.forName(jobClassName);
                Class<?>[] interfaces = clazz.getInterfaces();
                for (Class<?> anInterface : interfaces) {
                    if (anInterface == BaseJob.class){
                        continue a;
                    }
                }
                iterator.remove();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
        return pageResponseDto;
    }
}
